﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using com.lover.astd.common.model;
using com.lover.common;
using com.lover.astd.common.logic;
using com.lover.astd.game.ui.server;
using com.lover.astd.common;
using com.lover.astd.game.ui.server.impl.logger;
using com.lover.astd.common.model.battle;

namespace com.lover.astd.game.ui
{
    public partial class TempServerForm : Form
    {
        private MainForm _frm;
        public TempServerForm(MainForm frm)
        {
            _frm = frm;
            InitializeComponent();
        }

        private void btn_melt_Click(object sender, EventArgs e)
        {
            if (combo_store_equips.SelectedValue == null)
            {
                UiUtils.getInstance().info("还没有选择装备");
                return;
            }
            Dictionary<string, string> conf = new Dictionary<string, string>();
            conf.Add("equipId", combo_store_equips.SelectedValue.ToString());
            _frm.addTempServer("equip_melt", conf);
            this.Close();
        }

        private void btn_init_melt_Click(object sender, EventArgs e)
        {
            ILogger logger = new TempLogger(_frm);
            ProtocolMgr proto = new ProtocolMgr(_frm.GameUser, logger, _frm, _frm.Gameurl, _frm.JSessionId);
            List<Equipment> equips = ServiceFactory.getEquipManager().getStoreCanMelt(proto, logger, _frm.GameUser);
            combo_store_equips.DataSource = equips;
            combo_store_equips.DisplayMember = "Name";
            combo_store_equips.ValueMember = "Id";
            btn_melt.Enabled = true;
        }

        private void btn_init_campaign_Click(object sender, EventArgs e)
        {
            ILogger logger = new TempLogger(_frm);
            ProtocolMgr proto = new ProtocolMgr(_frm.GameUser, logger, _frm, _frm.Gameurl, _frm.JSessionId);
            List<CampaignItem> campaigns = ServiceFactory.getCampaignManager().getCampaigns(proto, logger);
            if (campaigns == null) { UiUtils.getInstance().info("未找到战役"); return; }
            combo_campains.DataSource = campaigns;
            combo_campains.DisplayMember = "Name";
            combo_campains.ValueMember = "ID";
            btn_campaign.Enabled = true;
        }
        private void btn_campaign_Click(object sender, EventArgs e)
        {
            if (combo_campains.SelectedValue == null)
            {
                UiUtils.getInstance().info("还没有选择打哪个");
                return;
            }
            int count = (int)num_campaign_count.Value;
            Dictionary<string, string> conf = new Dictionary<string, string>();
            string from_id = combo_campains.SelectedValue.ToString();
            conf.Add("from", from_id);
            conf.Add("count", count.ToString());
            _frm.addTempServer("campaign", conf);
            this.Close();
        }

        private void btn_init_wash_Click(object sender, EventArgs e)
        {
            ILogger logger = new TempLogger(_frm);
            ProtocolMgr proto = new ProtocolMgr(_frm.GameUser, logger, _frm, _frm.Gameurl, _frm.JSessionId);
            ServiceFactory.getHeroManager().getWashInfo(proto, logger, _frm.GameUser);
            List<Hero> heroes = _frm.GameUser.Heroes;
            if (heroes == null) { UiUtils.getInstance().info("未找到武将"); return; }
            combo_wash_heroes.DataSource = heroes;
            combo_wash_heroes.DisplayMember = "Desc";
            combo_wash_heroes.ValueMember = "Id";
            btn_start_wash.Enabled = true;
        }

        private void btn_start_wash_Click(object sender, EventArgs e)
        {
            if (combo_wash_heroes.SelectedValue == null)
            {
                UiUtils.getInstance().info("还没有选择洗哪个");
                return;
            }
            bool wash_tong = chk_wash_tong.Checked;
            bool wash_yong = chk_wash_yong.Checked;
            bool wash_zhi = chk_wash_zhi.Checked;
            if (!wash_tong && !wash_yong && !wash_zhi)
            {
                UiUtils.getInstance().info("大哥, 你洗啥都不选, 你想干啥, 你这是想洗将??");
                return;
            }
            string wash_what = "";
            wash_what += wash_tong ? "1" : "0";
            wash_what += wash_yong ? "1" : "0";
            wash_what += wash_zhi ? "1" : "0";

            Dictionary<string, string> conf = new Dictionary<string, string>();
            string wash_id = combo_wash_heroes.SelectedValue.ToString();
            conf.Add("wash_id", wash_id);
            conf.Add("wash_what", wash_what);
            _frm.addTempServer("wash", conf);
            this.Close();
        }
    }
}
